package me.project.android.client;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import javax.servlet.http.HttpServletRequest;
import me.project.common.exception.azzert.RonghuaAssert;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Configuration
public class Interceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        ServletRequestAttributes httpRequest = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        RonghuaAssert.isNotNull(httpRequest, "4001 参数错误");
        HttpServletRequest request = httpRequest.getRequest();
        requestTemplate.header("token",request.getHeader("token"));
    }
}